﻿using LowCoding.Common;
using SqlSugar;

namespace LowCoding.Application
{
    public class ServiceDb
    {
        public SqlSugarClient _client;

        public SqlSugarClient GetInstance(string conn)
        {
            string connectionstring = ConfigHelper.Configuration["ConnectionStrings:" + conn];
            var _client = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = DbType.MySql,
                ConnectionString = connectionstring,
                InitKeyType = InitKeyType.Attribute,
                IsAutoCloseConnection = true,
                AopEvents = new AopEvents
                {
                    OnLogExecuting = (sql, p) =>
                    {
                        //记录所有执行sql语句
                        LogHelper.WriteSqlLog(sql + "\r\n" + (p == null ? "" : string.Join(",", p.Select(it => it.ParameterName + ":" + it.Value))));
                    }
                }
            });
            return _client;
        }
    }
}